package main

import "fmt"

type rect struct {
	width, height int
}

// 计算矩形的面积
func (r *rect) area() int {
	fmt.Printf("area>the address of r is: %p \n", r)
	return r.width * r.height
}

// 计算矩形的周长
func (r rect) perim() int {
	fmt.Printf("perim>the address of r is: %p \n", &r)
	return 2*r.width + 2*r.height
}

// the address of r is: 0xc0000100e0
// area>the address of r is: 0xc0000100e0
// area:  50
// perim>the address of r is: 0xc0000100f0
// perim: 30
// area>the address of r is: 0xc0000100e0
// area:  50
// perim>the address of r is: 0xc000010100
// perim: 30
func main() {
	r := rect{width: 10, height: 5}
	fmt.Printf("the address of r is: %p \n", &r)
	fmt.Println("area: ", r.area())
	fmt.Println("perim:", r.perim())
	rp := &r
	fmt.Println("area: ", rp.area())
	fmt.Println("perim:", rp.perim())
}
